package com.ternnetwork.oa.controller.settings;

import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.JsonUtils;
import com.ternnetwork.oa.dto.settings.UserRelationshipDto;
import com.ternnetwork.oa.dto.settings.UserRelationshipQueryDto;
import com.ternnetwork.oa.service.settings.UserRelationshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;


@Controller
@RequestMapping("/settings/user/relationship/*")
public class UserRelationshipController {

    @Autowired
    private UserRelationshipService eventService;

    @RequestMapping("/save")
    public @ResponseBody BaseResponse add(String requestJson, Principal user) throws Exception {
        UserRelationshipDto dto= JsonUtils.jsonToObjectThrowsException(requestJson, UserRelationshipDto.class);
        return eventService.save(user.getName(),dto);
    }

    @RequestMapping("/findMyAll")
    public @ResponseBody BaseResponse findMyAll(Principal user,String type)  {
      return eventService.findAll(user.getName(),type);
    }

    @RequestMapping("/findByPage")
    public @ResponseBody BaseResponse findByPage(@PageableDefault Pageable pageable, UserRelationshipQueryDto dto, Principal user) {
        return eventService.findByPage(pageable, dto,user.getName());
    }

}
